//
// Created by Administrator on 2024/7/10.
//

#include "jtt809_header.h"

#include "msgpack/MessagePackWriter.h"
#include "msgpack/messagepack_reader.h"

using namespace protocol;

bool JTT809Header::tryGetEncryptKey(uint32_t &key) const {
    if (encryptFlag == 0x01) {
        key = encryptKey;
        return true;
    }
    return false;
}

void JTT809Header::serialize(MessagePackWriter &writer) {
    writer.writeUint(msgLength);
    writer.writeUint(msgSN);
    writer.writeUint(msgId);
    writer.writeUint(msgGnsscenterId);
    writer.writeBytes(versionFlag);
    writer.writeByte(encryptFlag);
    writer.writeUint(encryptKey);
    writer.writeTime(time);
}

void JTT809Header::deserialize(MessagePackReader &reader) {
    reader.decode();
    reader.readUint(msgLength);
    reader.readUint(msgSN);
    reader.readUint(msgId);
    reader.readUint(msgGnsscenterId);
    reader.readBytes(versionFlag);
    reader.readByte(encryptFlag);
    reader.readUint(encryptKey);
    reader.readTime(time);
}
